<?php

namespace App\Listeners;

use App\Events\RegistryAuditPass;
use App\Events\RegistryAuditReject;
use Overtrue\EasySms\EasySms;

class RegistryNotifySubscriber
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
    }

    public function handleRegistryAuditPass(RegistryAuditPass $event)
    {
        $user = $event->registry->user;
        $easySms = new EasySms(config('services.easy-sms'));
        $easySms->send($user->mobile, [
            'template' => 'SMS_232912068',
            'data' => [
                'name' => $user->nickname,
            ],
        ]);
    }

    public function handleRegistryAuditReject(RegistryAuditReject $event)
    {
        $user = $event->registry->user;
        $easySms = new EasySms(config('services.easy-sms'));
        $easySms->send($user->mobile, [
            'template' => 'SMS_232917070',
            'data' => [
                'name' => $user->nickname,
            ],
        ]);
    }

    public function subscribe($events)
    {
        $className = self::class;
        $events->listen(RegistryAuditPass::class, "{$className}@handleRegistryAuditPass");
        $events->listen(RegistryAuditReject::class, "{$className}@handleRegistryAuditReject");
    }
}
